/**
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 14/03/2004
 * Time: 14:24:37
 * To change this template use File | Settings | File Templates.
 */
package com.talios.jira.settings.projects;

import com.intellij.openapi.diagnostic.Logger;
import com.talios.jira.JiraException;
import com.talios.jira.browser.JiraProjectDetails;
import com.talios.jira.rpc.JiraRpcClient;

public class SettingsFactory {
    private static final Logger LOGGER = Logger.getInstance("Jira Browser");
    private static SettingsFactory ourInstance = new SettingsFactory();

    public static SettingsFactory getInstance() {
        return ourInstance;
    }

    private SettingsFactory() {
    }

    public ProjectSettings getSettingsEditorForProject(JiraProjectDetails project, String title) {
        ProjectSettings projectSettings;
        try {
            JiraRpcClient client = new JiraRpcClient(project.getServer());

            if (client.login()) {
                projectSettings = new RPCProjectSettings(project, client, title);
            } else {
                projectSettings = new SimpleProjectSettings(project, title);
            }
        } catch (JiraException e) {
            LOGGER.info("Problem checking RPC Support", e);
            projectSettings = new SimpleProjectSettings(project, title);
        }

        return projectSettings;
    }
}
